#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtCore>
#include <QtGui>
#include <QtSql>
#include <QtXml>
#include <QtNetwork>
#include "manualwidget.h"
#include "rardelegate.h"
#include "tabmodel1.h"
#include "editwidget.h"
#include "dbdialog.h"
#include "backupwidget.h"
#include "restorewidget.h"
#include "albumdialog.h"
#include "contacts.h"
#include "styledialog.h"
#include "norwegianwoodstyle.h"
#include "filterdialog.h"
#include "copydialog.h"
#include "addimage.h"
#include "adddocument.h"
#include "collattr.h"
#include "saveasdialog.h"
#include "savedocdialog.h"
#include "savexmldialog.h"
#include "graphicsview.h"
#include "chartwidget.h"
#include "catrowwidget.h"
#include "auctrowwidget.h"
#include "georowwidget.h"
#include "otherrowwidget.h"
#include "xmlimportdialog.h"
#include "xmltabledialog.h"
#include "xmlparse.h"
#include "xmltabmodel.h"
#include "setviewdialog.h"
#include "charswidget.h"
#include "codecs.h"
#include "previewhtmlwidget.h"
#include "schema.h"
#include "changestatusdialog.h"
#include "printview.h"
#include "valuewidget.h"
#include "selectcollectiondialog.h"
#include "selectcollectiondialog1.h"
#include "createdoc.h"
#include "printdocdialog.h"
#include "progressdialog.h"
#include "updatevaluesdialog.h"
#include "querywidget.h"
#include "connectiondialog.h"
#include "browserwidget.h"
#include "sqliteexpdialog.h"
#include "download.h"
#include "ui_mainwindow.h"

typedef struct
{
QString field;
QLabel * label_p;
QLineEdit * lineEdit_p;
}
SchemaViewItem;

class MainWindow: public QMainWindow, private Ui::MainWindow
{
Q_OBJECT

public:

MainWindow( QString default_font_str_arg );
~MainWindow();
void check_ru();
void check_de();
void check_en();
//void check_zh_CN();

public slots:

void open_db();
void close_app();
void index_selected(QModelIndex index);
void im_index_selected(QModelIndex index);
void commit_main( QSqlRecord record,
                  QModelIndex index,
                  bool new_item,
                  bool fast_update );
void edit_record();
void run_query();
void add_record();
void delete_record();
void copy_record();
void run_backup();
void run_restore();
void set_view(QModelIndex index);
void set_empty_view();              
void disconnect_db();
void close_album();
void albums();
void set_album( QString table,
                QString num,
                QString name );
void update_actions(bool state);               
void set_data( QString table,
               QModelIndex index,
               QLatin1String data_type );
void delete_models();
void delete_binary_models();
void delete_references_models();
void del_im_row();
void del_doc_row();
void del_cat_row();
void del_auct_row();
void del_geo_row();
void del_other_row();
void show_contacts();
void select_style();
void set_filter(bool f);
void add_image();
void add_document();
void tab_ind_changed(int ind);
void tab_ind_changed_rel(int ind);
void tab_ind_changed_refer(int ind);
void tab_ind_changed_binary(int ind);
void set_reverse_icon();
void set_obverse_icon();
void set_edge_icon();
void set_font();
void album_attr();
void show_image_double_clicked(QModelIndex index);
void show_image_rmb();
void show_image_button();
void save_image_as();
void show_charts();
void set_back();
void set_next();
void load_attrs();
void save_doc_as();
void show_full_rev();
void show_full_obv();
void show_full_edge();
void save_desc();
void switch_to_ru(bool);
void switch_to_en(bool);
void switch_to_de(bool);
//void switch_to_zh_CN(bool);
void add_cat_row();
void edit_cat_row();
void add_auct_row();
void edit_auct_row();
void add_geo_row();
void edit_geo_row();
void add_other_row();
void edit_other_row();
void commit_rel( QSqlRecord record,
                 QModelIndex index,
                 QLatin1String id,
                 bool new_item );
void cat_index_selected();
void auct_index_selected();
void geo_index_selected();
void other_index_selected();
void update_gl_tested(bool tested, int size);
void import_dialog();
void image_to_clipboard();
void delete_all_rows();
void show_creds();
void show_manual();
void conf_view();
void remember_ru( bool t );
void remember_de( bool t );
void remember_en( bool t );
//void remember_zh_CN( bool t );
void set_default_font();
void show_chars();
void export_xml();
void show_codecs();
void update_edit_button();
void preview_html();
void print_item();
void print_file();
void show_value();
void print_pricelist();
void print_report();
void print_pdf();
void fast_update();
void read_indicies(QString table);
void browse_db();
void export_sqlite();
void show_downloaded( QByteArray b );
void copy_downloaded( QByteArray b );
void save_downloaded( QByteArray b, QString p );
void get_download( Download * d,
                   bool ok,
                   QString s,
                   QString p,
                   QString e );

private:

QString db_root;
QString db_name;
QString db_user;
QString db_passwd;
QPalette originalPalette;
QModelIndex view_index;
QSqlRecord view_record;
QString opened_album;
QString opened_album_name;
QString opened_album_num;
int blocking;
int number_of_collections;

QMap<int, int> asc_index_columns;
QMap<int, int> desc_index_columns;
QList<SchemaViewItem> list_string_view_items;
QList<SchemaViewItem> list_int_view_items;
QMap<QString, QStringList> collection_attrs;
QString filter_;
bool html_text;

void delete_rows( QTableView * tView,
                  bool remove_files );
void change_style( QString s, QString st );
QSqlRecord construct_record( QString table_type,
                             qint64 id );
bool check_index();
void set_icon(QString side);
void show_icon(QString side);
QStringList attr_query( QString column_name,
                        QString table_string );
void show_image( bool double_clicked,
                 QString image_type,
                 QModelIndex index );                       
bool write_byte_array( QString file_name,
                       QByteArray ba );
void show_full( QString side, QString viewer_type );
void show_desc();
QTranslator * appTranslator;
QTranslator * qtTranslator;
bool gl_tested;
int max_size;
bool buildin_db;
QString last_im_dir;
QString last_doc_dir;
QString last_image_save_dir;
QString last_exp_save_dir;
bool other_data_set;
bool geo_data_set;
bool auctions_data_set;    
bool catalogs_data_set;
bool images_data_set;
bool documents_data_set;
bool desc_data_set;
bool icons_data_set;
void set_album_view( QString album );
QMap<int, int> columns_show;
QMap<int, int> column_width;
bool db_opened;
void close_db();
void set_default_view( QString album );
void writeSettings();
void readSettings();
QString default_font_str;
QString process_value( int i, QVariant v, bool append_comma );
QString preprocess_fast_update( QMap<QString, QVariant> m );
QString preprocess_varchar( QString s, int x );
QPixmap create_splash_image();
QString lang;
bool test_files( QString, QString );
QMovie * m0;
QMovie * m1;

protected:

void closeEvent(QCloseEvent * e);

};
#endif // MAINWINDOW_H


